using System;
using System.Collections.Generic;
using UnityEngine;
using Framework;

namespace GameCore
{
    public class ObjectSorter : MonoBehaviour
    {
        public string layerName;
        public float layerDistance = 0.01f;
        public int sortingIndex;
        
        public int SortingOrder
        {
            get => GetSortingIndex();
            set => SetSortingIndex(value);
        }
        
        public int GetSortingIndex() => sortingIndex;
        private void SetSortingIndex(int value)
        {
            var pos = transform.position;
            pos.z = value * -layerDistance;
            transform.position = pos;
            sortingIndex = value;
        }

        public void SetTop()
        {
            ObjectSortingManager.SetTop(this);
        }

        private void Start()
        {
            ObjectSortingManager.AddSortable(this);
        }
        
    }
}